package com.fyl.core.response;

import com.fyl.core.advance.constant.IResponseEnum;
import com.fyl.core.advance.constant.enums.CommonResponseEnum;

public class RS<T> extends BaseResponse {

    protected T data;

    public RS(IResponseEnum responseEnum, T data) {
        super(responseEnum);
        this.data = data;
    }

    public RS(T data) {
        super();
        this.data = data;
    }

    public T getData() {
        return data;
    }

    public RS<T> setData(T data) {
        this.data = data;
        return this;
    }

    public static <T> RS<T> genSuccess() {
        return new RS<>(CommonResponseEnum.SUCCESS, null);
    }

    public static <T> RS<T> genSuccess(T data) {
        return new RS<>(CommonResponseEnum.SUCCESS, data);
    }

    public static <T> RS<T> genFail(int code, String message) {
        return new RS<>(new IResponseEnum() {
            @Override
            public int getCode() {
                return code;
            }

            @Override
            public String getMessage() {
                return message;
            }
        }, null);
    }

    public static <T> RS<T> genFail(String message) {
        return new RS<>(new IResponseEnum() {
            @Override
            public int getCode() {
                return 500;
            }

            @Override
            public String getMessage() {
                return message;
            }
        }, null);
    }

    public static <T> RS<T> genFail(IResponseEnum responseEnum) {
        return new RS<>(responseEnum, null);
    }

}
